﻿using SpiderStudy.Utils.Currency;
using SpiderStudy.Utils.Html;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpiderStudy.WebSite.Baidu
{
    class BaiduSearchTool
    {
      
        string API = "https://www.baidu.com/s?wd={0}&ie=UTF-8";

        /// <summary>
        /// 获取百科关键词
        /// </summary>
        /// <param name="Keys"></param>
        /// <returns></returns>
        public string GetBaikekeys(string Keys)
        {
            string Shtml = WebHelper.HttpGet(string.Format(API,
              new  TextHelper().UrlEncodeToUtf8(Keys)));
            string Content = HtmlHelper.GetFirstValue(HtmlHelper.GetHtmlValueList(Shtml, "//div[@id='content_left']"));
            string TempKey = "";
            foreach (string Line in TextHelper.RegexTextList(Content, "mu=\".*?\""))
            {
                TempKey = TextHelper.ReplaceText(Line, "(mu=\"https://baike.baidu.com/item/|/[0-9]{0,200}\")", "");
                Console.WriteLine(TempKey);
                if (TempKey != "")
                    break;
            }

            return TempKey;
        }
    }
}
